// // No.4 online searching
#include <stdbool.h>
#include <stdio.h>
int main()
{
  int NUM_in; //number of input integer
  scanf("%d", &NUM_in);
  int i, temp, Test_SUM = 0, Final_SUM = 0;
  int record_left = 0, record_right = 0, temp_left, temp_first;
  bool if_record = false, if_all_negative = true;
  for (i = 0; i < NUM_in; i++)
  {
    scanf("%d", &temp);
    if (i == 0)
    {
      temp_first = temp;
    }
    Test_SUM += temp;
    if (!if_record)
    {
      temp_left = temp;
      if_record = true;
    }
    if (Test_SUM > Final_SUM)
    {
      Final_SUM = Test_SUM;
      record_right = temp;
      record_left = temp_left;
    }
    else if (Test_SUM < 0)
    {
      Test_SUM = 0;
      if_record = false;
    }
    if (temp >= 0)
      if_all_negative = false;
  }
  if (if_all_negative)
  {
    record_left = temp_first;
    record_right = temp;
  }

  printf("%d %d %d", Final_SUM, record_left, record_right);
  return 0;
}
